package com.ts.led;

import android.app.Service;
import android.content.Intent;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.os.IBinder;
import android.util.Log;

public class Ledserver extends Service {
    private Camera mCamera = null;
    private Parameters mParm = null;
    public static final String LED_STATE = "led_status";

    @Override
    public void onCreate() {
        Log.e("xiajy", "onCreate");
        mCamera = Camera.open();
        mCamera.startPreview();
    }

    @Override
    public IBinder onBind(Intent arg0) {
        Log.e("xiajy", "onBind");
        //Settings.System.putInt(getContentResolver(), LED_STATE, 1);
        mParm = mCamera.getParameters();
        mParm.setFlashMode(Parameters.FLASH_MODE_TORCH);
        mCamera.setParameters(mParm);
        return this.onBind(arg0);
    }

    @Override
    public boolean onUnbind(Intent intent) {
        Log.e("xiajy", "onUnbind");
        //Settings.System.putInt(getContentResolver(), LED_STATE, 0);
        mParm = mCamera.getParameters();
        mParm.setFlashMode(Parameters.FLASH_MODE_OFF);
        mCamera.setParameters(mParm);
        mCamera.release();
        mCamera = null;
        return super.onUnbind(intent);
    }

    @Override
    public void onStart(Intent intent, int startId) {
        Log.e("xiajy", "onStart");
        //Settings.System.putInt(getContentResolver(), LED_STATE, 1);
        mParm = mCamera.getParameters();
        mParm.setFlashMode(Parameters.FLASH_MODE_TORCH);
        mCamera.setParameters(mParm);
    }

    @Override
    public void onDestroy() {
        Log.e("xiajy", "onDestroy");
        //Settings.System.putInt(getContentResolver(), LED_STATE, 0);
        mParm = mCamera.getParameters();
        mParm.setFlashMode(Parameters.FLASH_MODE_OFF);
        mCamera.setParameters(mParm);
        mCamera.release();
        mCamera = null;
    }
}
